package controller;

import aop.LogData;
import aop.LogType;
import com.github.pagehelper.PageInfo;
import entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.PermissionService;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author Administrator
 * @create 2020.06.19 下午 4:53
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

//    @LogData(logType = LogType.LOGIN,description = "查看权限列表")
    @ResponseBody
    @GetMapping("/list")
    public MyResult<List<Permission>> layList(LayRequest layRequest){
        PageInfo<Permission> rolePageInfo=permissionService.selectByMap(layRequest);
        return new MyResult<>(0,rolePageInfo.getTotal(),rolePageInfo.getList());
    }
    @RequestMapping("/toAdd")
    public String toAdd(ModelMap modelMap){
        List<Permission> permissionList = permissionService.selectAll();
        modelMap.addAttribute("per",permissionList);
        return "add.jsp";
    }
    @LogData(logType = LogType.INSERT,description = "添加权限")
    @ResponseBody
    @RequestMapping("/add")
    public MyResult insert(Permission permission){
        boolean b = permissionService.insert(permission);
        return new MyResult(0);
    }
}
